﻿using CubicFWNet.Data.Models;
using CubicFWNet.Data.SystemManager;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CubicFWNet.Application.SystemManager
{
    public class NewsTypeApp
    {
        private NewsTypeRepository _newsTypeRepository = new NewsTypeRepository();
        public List<NewsType> GetLearningList()
        {
            return _newsTypeRepository.IQueryable(t =>t.Class == 2).ToList();
        }
        public int AddOrUpdate(NewsType newstype)
        {
            if (newstype.Id == Guid.Empty)
            {
                newstype.Id = Guid.NewGuid();
                return _newsTypeRepository.Insert(newstype);
            }
            else
            {
                return _newsTypeRepository.Update(newstype);
            }
        }

        public NewsType GetForm(Guid id)
        {
            return _newsTypeRepository.FindEntity(a => a.Id == id);
        }
        public int Delete(Guid id)
        {
            var del = _newsTypeRepository.FindEntity(u => u.Id == id);
            if (del == null) return -404;
            return _newsTypeRepository.Delete(a => a.Id == id);
        }
    }
}
